package com.bdzl.admin.controller.data;

import com.bdzl.admin.service.data.BankcardService;

import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.data.BankcardDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 银行卡信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:57:43
 */

@Controller
@RequestMapping("/bdzl/bankcard")
public class BankcardController extends BaseController {
	@Autowired
	private BankcardService bankcardService;

	@GetMapping()
	String Bankcard(){
	    return "bdzl/bankcard/bankcard";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<BankcardDO> bankcardList = bankcardService.list(query);
		int total = bankcardService.count(query);
		PageUtils pageUtils = new PageUtils(bankcardList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/bankcard/add";
	}

	@GetMapping("/edit/{bcId}")
	R edit(@PathVariable("bcId") Integer bcId){
		BankcardDO bankcard = bankcardService.get(bcId);
	    return R.ok(bankcard);
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody BankcardDO bankcard){
		int a = bankcardService.save(bankcard);
		if(a>0){
			R r = new R();
			r.put("bcId",a);
			return r;
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody BankcardDO bankcard){
		bankcardService.update(bankcard);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( @RequestParam("bcId") Integer bcId){
		if(bankcardService.remove(bcId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] bcIds){
		bankcardService.batchRemove(bcIds);
		return R.ok();
	}




}
